import com.gkj.blog.business.service.ResourcesService;
import com.gkj.blog.business.service.UserService;
import com.gkj.blog.business.vo.entity.Resources;
import com.gkj.blog.business.vo.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CustomRealm extends AuthorizingRealm {
        /**
         * 提供账户信息返回认证信息（用户的角色信息集合）
         *
         */
        @Override
        protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
            //获取用户的输入的账号.
            String username = (String) token.getPrincipal();

            User user=new User();
            user.setUsername(username);
            user.setPassword("566674082dacada7311dd0b58a46c6d3");

            SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
                    username,
                    user.getPassword(),
                    ByteSource.Util.bytes("salt"),
                    getName()
            );
            return authenticationInfo;
        }

        /**
         * 权限认证，为当前登录的Subject授予角色和权限（角色的权限信息集合）
         */
        @Override
        protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
         return null;
        }
}
